﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Transport
{
    public class LoaiDatXeControl
    {
        transportEntities db;

        public LoaiDatXeControl()
        {
            db = new transportEntities();
        }

        public loai_dat_xe findByID(string Id)
        {
            try
            {
                return db.loai_dat_xe.SingleOrDefault(t => t.ma_dat_xe == Id);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public loai_dat_xe findByName(string Name)
        {
            try
            {
                return db.loai_dat_xe.SingleOrDefault(t => t.ten_loai_dat_xe == Name);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public string getTypeId(string Name)
        {
            try
            {
                return db.loai_dat_xe.SingleOrDefault(t => t.ten_loai_dat_xe == Name).ma_dat_xe;
            }
            catch (Exception)
            {
                return "";
            }
        }

        public bool insert(loai_dat_xe value)
        {
            try
            {
                db.loai_dat_xe.AddObject(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool update(loai_dat_xe value)
        {
            try
            {
                loai_dat_xe st = db.loai_dat_xe.SingleOrDefault(t => t.ma_dat_xe == value.ma_dat_xe);
                st = value;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool delete(string Id)
        {
            try
            {
                loai_dat_xe st = db.loai_dat_xe.SingleOrDefault(t => t.ma_dat_xe == Id);
                db.loai_dat_xe.DeleteObject(st);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}